<?php
namespace app\middleware\admin;

use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;

use Tinywan\Jwt\JwtToken;
use Tinywan\Jwt\Exception\JwtTokenExpiredException;

class AdminCheck implements MiddlewareInterface
{
    public function process(Request $request, callable $handler) : Response
    {
    	$controller = $request->controller;
    	$ignore = ['app\admin\controller\AuthController'];

        if(!in_array($controller, $ignore))
        {
            $session = $request->session();
            $admin_info = $session->get('admin_info');
            if (empty($admin_info)) {

                return redirect('/admin/auth/login');
            }else{
                $request->admin_info = $admin_info;
            }
        }
        return $handler($request);
    }
}